package com.baidu.bos.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.baidu.bos.dao.IFunctionDao;
import com.baidu.bos.dao.base.BaseDaoImpl;
import com.baidu.bos.domain.Function;

@Repository
public class FunctionDaoImpl extends BaseDaoImpl<Function> implements IFunctionDao{

	public List<Function> findFunctionByUserid(String uid) {
		String sql = "from Function f left outer join fetch f.roles r " +
				"left outer join fetch r.users u where u.id = ?";
		List<Function> list = this.getHibernateTemplate().find(sql, uid);
		return list;
	}
	
	public List<Function> findAllMenu() {
		String hql = "from Function f where f.generatemenu = '1' order by f.zindex asc";
		return this.getHibernateTemplate().find(hql);
	}

	public List<Function> findMenu(String id) {
		String hql = "select distinct f from Function f left outer join fetch f.roles r " +
				"left outer join fetch r.users u where u.id = ? and f.generatemenu = '1' order by f.zindex asc";
		return this.getHibernateTemplate().find(hql,id);
	}

	public List<Function> findAdminMenu() {
		String hql = "from AdminFunction af where af.generatemenu = '1' order by af.zindex asc";
		return this.getHibernateTemplate().find(hql);
	}

}
